﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PeekService;

namespace PeekWebApp.handler
{
    /// <summary>
    /// ResetPasswordHandler 的摘要说明
    /// </summary>
    public class ResetPasswordHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                context.Response.ContentType = "text/plain";
                string code = context.Request["p"];
                string password =context.Server.HtmlDecode(context.Request["password"]);
                UserRegistry user = new UserRegistryService().GetAll().Find(o => o.Code.Equals(code));
                if (user != null)
                {
                    user.PassWord = DecryptService.Encrypt(password);
                    user.UserName = DecryptService.Encrypt(user.UserName);
                    user.Email = DecryptService.Encrypt(user.Email);
                    user.ConfirmPassWord = DecryptService.Encrypt(user.ConfirmPassWord);
                    new UserRegistryService().Update(user);
                    context.Response.Write("1");
                }                              
            }
            catch
            {
                context.Response.Write("0");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}